/**
 * Created by liubin on 2015/10/8.
 */
'use strict';

import Joi from 'joi';
import React from 'react';
import { connectReduxForm } from 'redux-form';
import JoiOption from '../tools/joiOption';
import joiValidator from '../tools/joiValidator';
import ValidateComponent from 'common/validateComponent';

const schema = {
    code: JoiOption(Joi.string().required().label('编码')),
    name: JoiOption(Joi.string().required().label('名称'))
};

@connectReduxForm({
    form: 'roleAdd',
    fields: ['code', 'name'],
    validate: joiValidator(schema)
})
class RoleAddForm extends ValidateComponent {
    static propTypes = {
        handleSubmit: React.PropTypes.func.isRequired
    }
    render() {
        const { fields: { code, name }, handleSubmit,handleBack } = this.props;
        return (
            <Form onSubmit={handleSubmit}>
                <FormGroup success={this.getSuccess(code)} error={this.getError(code)}>
                    <Label control sm={2} htmlFor='code'>编码</Label>
                    <Col sm={10}>
                        <Input type='text' id='code' {...code} placeholder='请输入权限编码' />
                        <HelpBlock>{this.getMessage(code)}</HelpBlock>
                    </Col>
                </FormGroup>
                <FormGroup success={this.getSuccess(name)} error={this.getError(name)}>
                    <Label control sm={2} htmlFor='name'>名称</Label>
                    <Col sm={10}>
                        <Input type='text' id='name' {...name} placeholder='请输入名称' />
                        <HelpBlock>{this.getMessage(name)}</HelpBlock>
                    </Col>
                </FormGroup>
                <Col xs={12} className='text-right' style={{marginBottom: 10}}>
                    <ButtonToolbar style={{display: 'inline-block'}} >
                        <Button type='button' bsStyle='default' onClick={handleBack}>取消</Button>
                        <Button type='submit' bsStyle='primary'>提交</Button>
                    </ButtonToolbar>
                </Col>
            </Form>
        );
    }
}

export default RoleAddForm;